#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Last Update: 2010/10/30 11:32:57

'''绝对坐标转相对坐标
'''

__revision__ = '0.1'
__author__ = 'lxd'

import wx

class MainFrame(wx.Frame):
    def __init__(self, log,**kwargs):
        wx.Frame.__init__(self, None, -1, 'name', size=(300, 250))
        self.log = log
        self.lblCenter = wx.StaticText(self, -1, u'中心原点坐标')
        self.txtCenter = wx.TextCtrl(self, -1, '478,373')
        self.lblOriginal = wx.StaticText(self, -1, u'绝对坐标')
        self.txtOriginal = wx.TextCtrl(self, -1)
        self.btnCal = wx.Button(self, -1, u'计算')
        self.lblResult = wx.StaticText(self, -1, u'结果')
        self.txtResult = wx.TextCtrl(self, -1)
        self.Bind(wx.EVT_BUTTON, self.OnCalClick, self.btnCal)  
        self.layout()

    def layout(self):
        self.Center()
        userSizer = wx.FlexGridSizer(cols=2, hgap=5, vgap=5)
        userSizer.AddGrowableCol(1)
        userSizer.Add(self.lblCenter, 0, wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL)
        userSizer.Add(self.txtCenter, 0, wx.EXPAND)
        userSizer.Add(self.lblOriginal, 0, wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL)
        userSizer.Add(self.txtOriginal, 0, wx.EXPAND)
        userSizer.Add((0, 0))
        userSizer.Add(self.btnCal, 0)
        userSizer.Add(self.lblResult, 0, wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL)
        userSizer.Add(self.txtResult, 0, wx.EXPAND)

        mainSizer = wx.BoxSizer(wx.VERTICAL)
        mainSizer.Add(userSizer, 0, wx.EXPAND|wx.ALL, 5)

        self.SetSizer(mainSizer)
        
    def OnCalClick(self, evt):
        """可以多维坐标计算
        """
        center_pos= map(int, self.txtCenter.GetValue().split(','))
        original_pos= map(int, self.txtOriginal.GetValue().split(','))
        r = ''
        for i in range(len(original_pos)):
            r += str(original_pos[i] - center_pos[i%2]) + ','
        self.txtResult.SetValue(r[:-1])


if __name__ == '__main__':
    app = wx.PySimpleApp()
    main = MainFrame(None)
    main.Show()
    app.MainLoop()

